using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace PeoplesJukebox.Core.Configuration
{
    /// <summary>
    /// Collection of configured tracklists
    /// </summary>
    [ConfigurationCollection(typeof(TrackList), 
        AddItemName="trackList", 
        CollectionType=ConfigurationElementCollectionType.BasicMap)]
    public class TrackListCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Returns a new colleciton element
        /// </summary>
        /// <returns>New TrackList</returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new TrackList();
        }

        /// <summary>
        /// Returns the collection key value
        /// </summary>
        /// <param name="element">Tracklist element</param>
        /// <returns>Tracklist key value</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((TrackList)element).Priority;
        }

        /// <summary>
        /// Returns the element name used for serializing the collection
        /// </summary>
        protected override string ElementName
        {
            get { return "trackList"; }
        }

        /// <summary>
        /// Returns the collection type used (BasicMap)
        /// </summary>
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        /// <summary>
        /// Gets the tracklist at the given index
        /// </summary>
        /// <param name="index">Tracklist index</param>
        /// <returns>Tracklist</returns>
        public TrackList this[int index]
        {
            get { return (TrackList)base.BaseGet(index); }
        }
    }
}
